#pragma once


class CRenderClip
{
public:
    CRenderClip(XCANVAS xCanvas, const RECT* prcItem)
    {
        if(prcItem == NULL)
        {
            m_xCanvas = NULL;
            m_hOldClip = NULL;
        }
        else
        {
            m_xCanvas = xCanvas;
            m_hOldClip = ::CreateRectRgn(0, 0, 0, 0);
            ::GetClipRgn((HDC)m_xCanvas, m_hOldClip);

            HRGN hItemClip = ::CreateRectRgn(prcItem->left, prcItem->top, prcItem->right, prcItem->bottom);
            if(hItemClip != NULL)
            {
                ::ExtSelectClipRgn((HDC)m_xCanvas, hItemClip, RGN_AND);
                ::DeleteObject(hItemClip);
            }
        }
    }
    ~CRenderClip()
    {
        if(m_xCanvas != NULL)
        {
            if(m_hOldClip != NULL)
            {
                ::ExtSelectClipRgn((HDC)m_xCanvas, m_hOldClip, RGN_COPY);
                ::DeleteObject(m_hOldClip);
                m_hOldClip = NULL;
            }

            m_xCanvas = NULL;
        }
    }

protected:
    XCANVAS m_xCanvas;
    HRGN    m_hOldClip;
};
